package com.yanqu.road.connect;

import com.yanqu.road.NettyMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.net.operator.ServerSessionGroupOperator;
import io.netty.channel.ChannelHandlerContext;

public class ServerLinkControl {

	private static ServerSessionGroupOperator serverSessionGroupOperator = new ServerSessionGroupOperator();

	private ServerLinkControl() {

	}

	public static void initServerLinkControl(int count) {
		serverSessionGroupOperator.setServerCount(count);
	}

	public static void removeLinkedClient(ChannelHandlerContext ctx) {
		ServerConnectionGroup client = ctx.channel().attr(NettyMgr.LINKED_CLIENT).get();
		if (client == null) {
			return;
		}
		serverSessionGroupOperator.remove(client.getConnectionId());
	}

	public static void send(long playerId, YanQuMessage packet) {
		serverSessionGroupOperator.sendPacket(packet, playerId);
	}

	public static void send(YanQuMessage packet) {
		send(packet.getPlayerId(), packet);
	}

	public static ServerConnectionGroup addServerSessionGroup(long serverIndex, YanQuConnection session, int count, int linkIndex) {
		return serverSessionGroupOperator.addSessionGroup(serverIndex, session, count, linkIndex);
	}
}
